package nodes;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import compiler.Compiler;
import compiler.SymbolTable;

import descriptors.AbstractDescr;

public class ListNode<T extends AbstractNode> extends AbstractNode implements Iterable<T> {

	private List<T> nodes;
	
	public ListNode(List<T> nodes,int line, int column){
		super(line,column);
		this.nodes=nodes;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public AbstractDescr compile(
			SymbolTable symbolTable, Compiler compiler) {
		for(T node:nodes){
			node.compile(symbolTable, compiler);
		}
		return null;
	}

	@Override
	public void print() {
		trace("ListNode");
		for(T node:nodes) node.print();
		unindent();
	}

	@Override
	public Iterator<T> iterator() {
		return nodes.iterator();
	}
	
	public List<T> toList(){
		return new ArrayList<T>(nodes);
	}
	
	public int size(){
		return nodes.size();
	}

}
